#===============================================================================
# Koro Business Environment
# Copyright (C) 2008,2010  Antonio Corroppoli
#
#This file is part of Koro BE.
# 
# Koro BE is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# Koro BE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Koro BE; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#===============================================================================

import wx
from koro.ui.wxgui.widgets import controls
from koro.ui.wxgui.pages import BasePage
from koro.ui.wxgui.mellcfg import mDefaultBorder


#===============================================================================
# AgendaPage
#===============================================================================
class AgendaPage(BasePage):
    TITLE="Impegni "
    def __init__(self,*args,**kwargs):
        BasePage.__init__(self,*args,**kwargs)
        
        self.data = controls.LabelDateCtrl(self,label='Data')
        self.ora = controls.LabelTimeCtrl(self,label='Ora')
        self.impegno = controls.LabelTextCtrl(self,label='Impegno',style=wx.TE_MULTILINE,maxlen=350,size=(-1,70))
        self.note = controls.LabelTextCtrl(self,label='Note',style=wx.TE_MULTILINE,maxlen=350,size=(-1,70))
        self.fatto = wx.CheckBox(self,label="Fatto",style=wx.ALIGN_RIGHT)
        
        self.__do_layout(args[2])
        #self.data.set_date(wx.DateTime_Now())
        self.__bind()
        #self.list_ctrl.load(self._objects_list)
        #self.list_ctrl.select(0,True)
        self.SetAutoLayout(True)
        #self.init_page_view()
    
    def __do_layout(self,objects):
        fieldsizer = wx.GridBagSizer(0,0)

        boxsizer=wx.BoxSizer(wx.VERTICAL)        

#        self.ID = controls.mTextCtrl(id=wx.NewId(), parent=self, size=(70, -1),mstyle=controls.mTE_READ_ONLY)
#        self.ID.Hide()
        #boxsizer.Add(controls.CompositeCtrl(self.ID,label='ID'),0,wx.ALL,border=mDefaultBorder)
        
        
        boxsizer.Add(self.data,0,wx.ALL,border=mDefaultBorder)
        
        boxsizer.Add(self.ora,0,wx.ALL,border=mDefaultBorder)
        
        boxsizer.Add(self.impegno,0,wx.ALL,border=mDefaultBorder)
        
        boxsizer.Add(self.note,0,wx.ALL,border=mDefaultBorder)
        
        boxsizer.Add(self.fatto,0,wx.ALL,border=mDefaultBorder)
        
        self.set_list_columns(controls.Column('Data',200,'get_scadenza_fmt'),
                              controls.Column('Impegno',300,'impegno'),
                              controls.Column('Note',300,'note'),
                              controls.Column('Fatto',100,'is_fatto_fmt'),
                              )
        self.load_list_objects(objects)
                
        fieldsizer.Add(boxsizer,(0,0),flag=wx.ALL|wx.EXPAND ,border=0)#riga zero colonna 0
        fieldsizer.Add(self.list_manager.get_managed_list(),(0,1),flag=wx.ALL|wx.EXPAND ,border=1)#riga zero colonna 1        
        fieldsizer.AddGrowableRow(0)
        fieldsizer.AddGrowableCol(1)
        
        self.Sizer.Add(fieldsizer,1,flag=wx.ALL|wx.EXPAND ,border=10)#riga zero colonna 1
    
    def __bind(self):
        #nella nuova versione l'evento wx.EVT_LIST_ITEM_SELECTED e' leganto da BasePanel
        #self.Bind(wx.EVT_LIST_ITEM_SELECTED,self._on_item_selected)
        pass        
    
    def update_fields(self,obj):
        print 'AgendaPage.update_fields'        
        #self.ID.SetValue(dataObj.get_ID_fmt())        
        self.data.set_value(obj.get_data())
        self.ora.set_value(obj.get_ora())
        self.impegno.set_value(obj.impegno)
        self.note.set_value(obj.note)
        self.fatto.SetValue(obj.fatto)
    
    def reset_fields(self):
        print 'AgendaPage.reset_fields'
        #self.ID.Clear()
        #self.data.set_value(wx.DateTime_Now())
        self.ora.set_value('00:00')
        self.impegno.clear()
        self.note.clear()                
        self.fatto.SetValue(False)        
    
    def update_object(self,obj):
        print 'AgendaPage.set_object'
        #obj.set_ID(self.ID.GetValue())
        obj.set_data(self.data.get_value())        
        obj.set_ora(self.ora.get_value())
        obj.impegno=self.impegno.get_value()
        obj.note=self.note.get_value()
        obj.fatto=self.fatto.GetValue()
    
    def reset_focus(self):
        self.impegno.set_focus()
    
#    def process_delete(self):
#        if self._page_state!=BasePage.NORMAL_STATE:
#            self.before_close()
#        else:
#            BasePage.process_delete(self)

#    def after_save(self):
#        self.update()
    
    def after_delete(self):
        self.update()
